package com.exam.danangtranel.adapter;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import com.exam.danangtranel.filed.Hotel;
import com.example.danangtravel.R;
import com.example.danangtravel.allMethod;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class TbHotelAdapter extends BaseAdapter {
	private Context context;
	public ArrayList<Hotel> array;
	private LayoutInflater inflater;
	static InputStream bitmap = null;
	static Hotel data;
	private allMethod getImage;

	public TbHotelAdapter(Context context, ArrayList<Hotel> arrayList) {
		this.context = context;
		this.array = arrayList;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		getImage = new allMethod(context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return array.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return array.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		data = array.get(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.row_hotel, null);
			holder.tvName = (TextView) convertView
					.findViewById(R.id.TvNameHotel);

			holder.imgHotel = (ImageView) convertView
					.findViewById(R.id.imgHotel);

			holder.rateHotel = (RatingBar) convertView
					.findViewById(R.id.rateHotel);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tvName.setText(data.getName());

		try {
			holder.imgHotel.setImageBitmap(getImage.getimg(data.getImage()));
		} catch (IOException e) {
			e.printStackTrace();
		}

		holder.rateHotel.setRating(data.getRating());
		return convertView;
	}

	static class ViewHolder {
		TextView tvName;
		ImageView imgHotel;
		RatingBar rateHotel;
	}

}
